package com.example.phone.home;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.phone.R;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;


public class BannerFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate( R.layout.fragment_banner, container, false );
        initBanner( view );
        return view;
    }

    //设置轮播图
    private void initBanner(View root) {
        Banner homeBanner;
        List<Integer> images = new ArrayList<Integer>();
        images.add( R.drawable.rotation1 );
        images.add( R.drawable.rotation2 );
        images.add( R.drawable.rotation3 );
        images.add( R.drawable.rotation4 );
        images.add( R.drawable.rotation5 );
        images.add( R.drawable.rotation6 );
        images.add( R.drawable.rotation7 );

        homeBanner = (Banner) root.findViewById( R.id.homeBanner );
        homeBanner.setImages( images );
        homeBanner.setBannerStyle( BannerConfig.CIRCLE_INDICATOR );
        homeBanner.setDelayTime( 3000 );
        homeBanner.setImageLoader( new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                Glide.with( context ).load( path ).into( imageView );
            }
        } );
        homeBanner.start();
    }
}
